//
//  DrawRectView.m
//  Quartz2D
//
//  Created by Yinyin Zeng on 22/4/20.
//  Copyright © 2020 MaoYeYeDeJiangCuCha. All rights reserved.
//

#import "DrawRectView.h"


@implementation DrawRectView


- (void)setProgressValue:(CGFloat)progressValue{
    _progressValue = progressValue;
    [self setNeedsDisplay];
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 */
- (void)drawRect:(CGRect)rect {
    
    NSArray *array = @[@0.12,@0.15,@0.10,@0.14,@0.08,@0.14,@0.17,@0.1];
    
    //柱状图
    
    for (int i = 0; i < array.count; ++i) {
        
        CGFloat w = 20;
        CGFloat h = 200 * [array[i]floatValue];
        CGFloat x = i * 2 * w + 50;
        CGFloat y = 200 - h;
        
        UIBezierPath *pathTwo = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, w, h)];
        [pathTwo fill];
        
    }

    
    UIBezierPath *pathThree = [UIBezierPath bezierPathWithArcCenter:CGPointMake(260, 260) radius:50 startAngle:0 - M_PI_2 endAngle:2*M_PI*self.progressValue - M_PI_2 clockwise:1];
    [pathThree addLineToPoint:CGPointMake(260, 260)];
    [pathThree fill];
    
    
    //饼图
    
    CGFloat start = 0;
    CGFloat end = 0;
    for (int i = 0; i < array.count; i++) {
        
        end = 2 * M_PI * [array[i] floatValue] + start;
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(rect.size.width*0.5, rect.size.height*0.5) radius:100 startAngle:start endAngle:end clockwise:1];
        
        [path addLineToPoint:CGPointMake(rect.size.width*0.5, rect.size.height*0.5)];
        
        [[UIColor colorWithRed:((float)arc4random_uniform(256) / 255.0) green:((float)arc4random_uniform(256) / 255.0) blue:((float)arc4random_uniform(256) / 255.0) alpha:1.0] set];
        
        [path fill];
        
        start = end;
        
    }
    
    
    //奇偶填充规则
    UIBezierPath *pathOne = [UIBezierPath bezierPathWithRect:CGRectMake(100, 700, 200, 100)];
    [pathOne addArcWithCenter:CGPointMake(150, 700) radius:50 startAngle:0 endAngle:2*M_PI clockwise:1];
    pathOne.usesEvenOddFillRule = YES;
    [[UIColor blackColor]set];
    [pathOne fill];
    
    
    
    
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self setNeedsDisplay]; //重绘
}


@end
